/**
 * 
 */
package metalink.admin;

import java.util.ArrayList;
import java.util.Vector;

import com.opensymphony.xwork2.ActionSupport;

import model.admin.HostelMo;

import vo.LibraryBookDetailsVo;
import vo.mixed.HostelStudentVo;
import java.util.Map;

import javax.servlet.http.HttpSession;

import org.apache.struts2.ServletActionContext;
/**
 * @author Sony
 *
 */
public class GetHostelRoomsList extends ActionSupport{
	private int residential_id;
	ArrayList<HostelStudentVo> studentDetailsList;
	HttpSession session;
	private int result;

	//------------ Pagination --------------//
	private int page;
    private String morepages;
	private Vector noofpages=new Vector();
	private int nextpage;
	private int currentpage;
	private String hasprevpage;
	private int prevpage;
	private int items;
	//private Vector pagelist=new Vector();
	private ArrayList<HostelStudentVo> pagelist;
	public String execute()
	{
		System.out.println("getting list of rooms in residential id : "+residential_id);
		studentDetailsList=new ArrayList<HostelStudentVo>();
		pagelist =new ArrayList<HostelStudentVo>();
		HostelMo mo = new HostelMo();
		//System.out.println("res id :"+residential_id);
		try {
			studentDetailsList=mo.getStudentsFromHostels(residential_id);
			session = ServletActionContext.getRequest().getSession();
			session.setAttribute("residential_id", residential_id);
		} catch (Exception e) {
			System.out.println(e.getMessage());
			addActionError(e.getMessage());
		}
result = studentDetailsList.size();
		
		//---------- Pagination ------------------//
		
		int p=getPage();
        if(p==0)
        {
            setHasprevpage("false");
        }
        else
        {
            setHasprevpage("true");
            setPrevpage(p-1);
        }

        setCurrentpage(p);

        int count;
        count=0;

        int size=studentDetailsList.size();
        setItems(size);
        int pagesinlist=size/15;
        while(count<=pagesinlist)
        {
            noofpages.add(count);
            count++;
        }
        count=0;
        while(count<15)
        {

            if(size>=(p*15)+count+1)
            {
                System.out.println(p);
                pagelist.add(studentDetailsList.get((p*15)+count));
                System.out.println((p*15)+count);
                System.out.println("size"+pagelist.size());
                count++;
                setMorepages("true");
                setNextpage(p+1);

            }
            else
            {
                setMorepages("false");
                break;
            }
        }
		return SUCCESS;
	}
	
	
	
	
	public ArrayList<HostelStudentVo> getStudentDetailsList() {
		return studentDetailsList;
	}

	public void setStudentDetailsList(ArrayList<HostelStudentVo> studentDetailsList) {
		this.studentDetailsList = studentDetailsList;
	}

	public int getResidential_id() {
		return residential_id;
	}

	public void setResidential_id(int residential_id) {
		this.residential_id = residential_id;
	}




	public int getResult() {
		return result;
	}




	public void setResult(int result) {
		this.result = result;
	}




	public int getPage() {
		return page;
	}




	public void setPage(int page) {
		this.page = page;
	}




	public String getMorepages() {
		return morepages;
	}




	public void setMorepages(String morepages) {
		this.morepages = morepages;
	}




	public Vector getNoofpages() {
		return noofpages;
	}




	public void setNoofpages(Vector noofpages) {
		this.noofpages = noofpages;
	}




	public int getNextpage() {
		return nextpage;
	}




	public void setNextpage(int nextpage) {
		this.nextpage = nextpage;
	}




	public int getCurrentpage() {
		return currentpage;
	}




	public void setCurrentpage(int currentpage) {
		this.currentpage = currentpage;
	}




	public String getHasprevpage() {
		return hasprevpage;
	}




	public void setHasprevpage(String hasprevpage) {
		this.hasprevpage = hasprevpage;
	}




	public int getPrevpage() {
		return prevpage;
	}




	public void setPrevpage(int prevpage) {
		this.prevpage = prevpage;
	}




	public int getItems() {
		return items;
	}




	public void setItems(int items) {
		this.items = items;
	}




	public ArrayList<HostelStudentVo> getPagelist() {
		return pagelist;
	}




	public void setPagelist(ArrayList<HostelStudentVo> pagelist) {
		this.pagelist = pagelist;
	}




	public HttpSession getSession() {
		return session;
	}




	public void setSession(HttpSession session) {
		this.session = session;
	}


}
